package org.wsiz.vro.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlTransient;

import org.apache.log4j.Logger;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.data.domain.Persistable;

import com.google.common.base.Objects;

/**
 * @author "Tomasz Marciniak"
 */
@Entity
@Table(name = "role")
public class Role implements Persistable<Integer> {
	private static final long serialVersionUID = 1L;

	@SuppressWarnings("unused")
	private static final Logger log = Logger.getLogger(Role.class);

	private Integer id;
	private String roleName;

	public Role() {
	}

	public Role(Integer primaryKey) {
		setId(primaryKey);
	}

	@Override
	@Transient
	@XmlTransient
	public boolean isNew() {
		return getId() == null;
	}

	@Column(name = "id", nullable = false, unique = true, precision = 10)
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Id
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@NotEmpty
	@Size(max = 255)
	@Column(name = "role_name", nullable = false, unique = true)
	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	/**
	 * Set the default values.
	 */
	public void initDefaultValues() {
	}

	@Override
	public boolean equals(Object other) {
		return this == other
				|| (other instanceof Role && hashCode() == other.hashCode());
	}

	/**
	 * hashCode implementation using a business key.
	 */
	@Override
	public int hashCode() {
		return Objects.hashCode(getRoleName());
	}

	/**
	 * Construct a readable string representation for this {@link Role}
	 * instance.
	 */
	@Override
	public String toString() {
		return Objects.toStringHelper(this) //
				.add("id", getId()) //
				.add("roleName", getRoleName()) //
				.toString();
	}
}